<template>
  <el-form :inline="inline" :model="formModel" ref="form" :label-position="labelPosition" name="form" :label-width="labelWidth">
    <el-form-item v-for="item in formLabel" :label="item.name" :key="item.model">
      <el-input v-model="formModel[item.model]" :placeholder="'请输入' + item.label" v-if="!item.type"></el-input>
      <el-select v-model="formModel[item.model]" placeholder="请选择" v-if="item.type === 'select'">
        <el-option v-for="(item, index) in item.opts" :key="index" :label="item.label.toString()" :value="item.label"></el-option>
      </el-select>
      <el-switch v-model="formModel[item.model]" v-if="item.type === 'switch'"></el-switch>
      <el-date-picker v-model="formModel[item.model]" type="date" placeholder="选择日期" v-if="item.type === 'datePicker'" value-format="yyyy-MM-dd">
      </el-date-picker>
      <el-date-picker
        v-model="formModel[item.model]"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"
        v-if="item.type === 'datePickerList'"
      >
      </el-date-picker>
    </el-form-item>
    <el-form-item><slot></slot></el-form-item>
  </el-form>
</template>

<script>
export default {
  name: "FormComponet",
  props: {
    inline: Boolean,
    formModel: Object,
    formLabel: Array,
    labelPosition: String,
    labelWidth: {
      type: String,
      default() {
        return "auto";
      }
    }
  }
};
</script>

<style scoped></style>
